package app.server.project.main.service.controller;

import app.server.project.core.constants.Def;
import app.server.project.core.http.CMSBasePage;
import app.server.project.core.http.CMSLstResp;
import app.server.project.core.http.RespModel;
import app.server.project.main.service.db.entity.user.UserIPEntity;
import app.server.project.main.service.dto.UserInfoReq;
import app.server.project.main.service.dto.cms.IpCountDto;
import app.server.project.main.service.dto.cms.LockAccountReq;
import app.server.project.main.service.dto.cms.UserInfoResp;
import app.server.project.main.service.dto.rank.CommonRankResp;
import app.server.project.main.service.dto.rank.GetRankReq;
import app.server.project.main.service.dto.rank.RankResp;
import app.server.project.main.service.service.IPService;
import app.server.project.main.service.service.UserInfoService;
import app.server.project.main.service.service.rank.RankService;
import app.server.project.main.service.service.rank.RankType;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 用户基础信息模块
 */
@AllArgsConstructor
@RestController
@RequestMapping("/userinfo")
public class UserInfoController {

    private UserInfoService userInfoService;
    private RankService rankService;
    private IPService ipService;

    /**
     * 获取指定用户基础信息
     *
     * @param
     * @return
     */
    @PostMapping("/getBaseInfo")
    public RespModel<UserInfoResp> getBaseInfo(@RequestBody UserInfoReq req) {
        return RespModel.success(this.userInfoService.getBaseInfo(req.getUserId()));
    }

    /**
     * 拉取日排行榜
     *
     * @param req
     * @return
     */
    @PostMapping("/getDayRank")
    public RespModel<RankResp> getDayRank(@RequestBody GetRankReq req, @RequestHeader(Def.UserId) long userId) {
        return RespModel.success(this.rankService.getRank(RankType.RANK_TYPE_DAY, req, userId));
    }

    /**
     * 拉取周排行榜
     *
     * @param req
     * @return
     */
    @PostMapping("/getWeekRank")
    public RespModel<RankResp> getWeekRank(@RequestBody GetRankReq req, @RequestHeader(Def.UserId) long userId) {
        return RespModel.success(this.rankService.getRank(RankType.RANK_TYPE_WEEK, req, userId));
    }

    /**
     * 获取邀请总榜
     *
     * @param userId
     * @return
     */
    @PostMapping("/getNeverExpireInviteRank")
    public RespModel<CommonRankResp> getNeverExpireInviteRank(@RequestHeader(Def.UserId) long userId) {
        return RespModel.success(this.rankService.getNeverExpireInviteRank(userId));
    }

    /**
     * 获取邀请日榜
     *
     * @param userId
     * @return
     */
    @PostMapping("/getInviteDayRank")
    public RespModel<CommonRankResp> getInviteDayRank(@RequestHeader(Def.UserId) long userId) {
        return RespModel.success(this.rankService.getInviteDayRank(userId));
    }

    /**
     * 获取邀请周榜
     *
     * @param userId
     * @return
     */
    @PostMapping("/getInviteWeekRank")
    public RespModel<CommonRankResp> getInviteWeekRank(@RequestHeader(Def.UserId) long userId) {
        return RespModel.success(this.rankService.getInviteWeekRank(userId));
    }

    @RequestMapping("/getUserIP")
    public CMSLstResp<UserIPEntity> getUserIP(UserInfoReq req) {
        return this.ipService.getUserIP(req.getUserId());
    }

    @RequestMapping("/getIpCount")
    public CMSLstResp<IpCountDto> getIpCount(CMSBasePage req) {
        return this.ipService.getIpCount(req);
    }

    @RequestMapping("/getAllPayerCountry")
    public CMSLstResp<IpCountDto> getAllPayerCountry(CMSBasePage req) {
        return this.ipService.getAllPayerCountry(req);
    }

    @RequestMapping("/canRank")
    public RespModel canRank(@RequestBody LockAccountReq lockAccountReq) {
        this.userInfoService.canRank(lockAccountReq);
        return RespModel.success();
    }
}
